package com.example.xiaomi.Model.Service;

import com.example.xiaomi.Model.Controller.DaoList;
import com.example.xiaomi.Model.entity.UeserEntity;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/gohome")
public class go_home extends HttpServlet {
    DaoList dao = new DaoList();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/plain;charset=utf-8");
        String arr = request.getParameter("arr");
        String[] segmentation = arr.split(",");
        PrintWriter out = response.getWriter();
        List<UeserEntity> inquire_All = dao.selectAll();
        String hint = null;
        if (segmentation[0].contains("@qq.com")){
            for (UeserEntity list: inquire_All) {
                if (segmentation[0].equals(list.getUpostbox()) && segmentation[1].equals(list.getUciche()) ){
                    hint = list.getUname()+","+list.getUid();
                    break;
                }else {
                    hint = "账号或者密码错误!";
                }
            }
        }else{
            for (UeserEntity list: inquire_All) {
                int id = Integer.parseInt(segmentation[0]);
                int mysql_Id = list.getUid();
                if (id == mysql_Id && segmentation[1].equals(list.getUciche()) ){
                    hint = list.getUname()+","+list.getUid();
                    break;
                }else{
                    hint = "账号或者密码错误!";
                }
            }
        }
        out.println(hint);
    }
}
